﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<title>Startup Template (ASP.NET Core)</title>
		<link type="text/css" rel="stylesheet" href="../bootstrap.min.css" />
	</head>

	<body>

		<div class="document-contents">

			<h3>Introduction</h3>
			<p>The easiest way of starting a new project using ABP with <strong>ASP.NET Core 
			MVC</strong> is to create a 
	template on <a href="/Templates">templates page</a>. Remember to check "<strong>Include 
		module zero</strong>". After creating and downloading your project, 
			follow below steps to run your application.</p>
			<ul>
				<li>Open your solution on <strong>Visual Studio 2017+</strong> 
				and <strong>build</strong> the solution.</li>
				<li>Select the '<strong>Web.Mvc</strong>' project as startup project.</li>
				<li>Open <strong>Package Manager Console</strong> and run <strong>
			Update-Database</strong> command to create your database (ensure 
			that Default project is selected as <strong>.EntityFrameworkCore</strong> 
			in the Package Manager Console window).</li>
				<li>Run the application.</li>
			</ul>
			
						<div class="bs-callout bs-callout-warning">
				<p>If you have problems with running the application, please try 
				close and open your Visual Studio again. It sometimes fail on 
				first package restore.</p>
			</div>


			<h4>Login</h4>
			<p>Once you run the application, you will see a login page as shown 
			below:</p>
					  <p>
		  <img class="img-thumbnail" alt="Login Page" height="654" src="../images/module-zero-core-template-ui-login.png" width="897" /></p>

			<p>User name is &#39;<strong>admin</strong>' and password is '<strong>123qwe</strong>' as default. 
			There is also a &quot;Default&quot; tenant by default. After login, you can 
			see the sample dashboard page:</p>
			<p>
		  <img class="img-thumbnail" alt="Dashboard" height="971" src="../images/module-zero-core-template-ui-home.png" width="1365" /></p>
			<h4>About Multi Tenancy</h4>
			<p>In this template, <strong>multi-tenancy is enabled by default</strong>. You 
	can disable it in Core project's module class if you don't need.</p>
			<h3>Social Logins</h3>
			<p>Startup template supports <strong>Facebook</strong>, <strong>Twitter</strong>, <strong>Google+ </strong> and <strong>Microsoft</strong> logins. In the web.config, you can see the 
	following settings in appsettings.json:</p>
			<pre lang="json">
 "Facebook": {
  "IsEnabled": "false",
  "AppId": "",
  "AppSecret": ""
},
"Google": {
  "IsEnabled": "false",
  "ClientId": "",
  "ClientSecret": ""
},
"Twitter": {
  "IsEnabled": "false",
  "ConsumerKey": "",
  "ConsumerSecret": ""
},
"Microsoft": {
  "IsEnabled": "false",
  "ConsumerKey": "",
  "ConsumerSecret": ""
}
			</pre>
			<p>Here, you can enable which you need. Surely, you must have application 
	keys and passwords which you need to get from related social web site. You 
	can find guides from web to learn how to obtain this keys. Once you enable a 
	social login and enter true keys, you will see a button in the login page. 
	You can implement other logins as similar.</p>
			<h3>Token Based Authentication</h3>
			<p>Startup template uses cookie based authentication for browsers. However, if you 
	want to consume Web APIs or application services (those are exposed via 
				<a href="/Pages/Documents/Dynamic-Web-API">dynamic 
	web api</a>) from a mobile application, you probably want a token based 
	authentication mechanism. Startup template includes JwtBearer token authentication 
	infrastructure.</p>
			<p>Here, <strong>Postman</strong> (chrome extension) will be used to demonstrate 
	requests and responses.</p>
			<h4>Authentication</h4>
			<p>Just send a <strong>POST</strong> request to <strong>http://localhost:62114/api/TokenAuth/Authenticate</strong> with <strong>Context-Type="application/json"</strong> header as shown below:</p>
			<p>
				<img class="img-thumbnail" alt="Request for token" src="../images/aspnet-core-token-auth.png" />
			</p>
			<p>We sent values <strong>usernameOrEmailAddress
            </strong>and <strong>password</strong>. As seen above, result property of returning JSON contains the token and expire time (which is 24 hours by default and can be configured). We can save it and use for next requests.</p>
			<div class="bs-callout bs-callout-warning">
				<p><strong>About Multi Tenancy<br>
				</strong>API will work as host users by default. You can send
				<strong>Abp.TenantId</strong> header value to work with a 
				specified tenant. It's an integer value and 1 for default tenant 
				by default.</p>
			</div>
			<h4>Use API</h4>
			<p>After authenticate and get the <strong>token</strong>, we can use it to call any <strong>authorized</strong> 
	action. All <strong>application services </strong>are available to be used remotely. For 
	example,  we can use the <strong>User service</strong> to get a <strong>list of users</strong>:</p>
			<p>
				<img class="img-thumbnail" alt="Authorization via token" src="../images/jwt-token-request.png" />
			</p>
			<p>Just made a <strong>GET</strong> request to <strong>http://localhost:62114/api/services/app/user/GetUsers</strong> with <strong>
	Content-Type="application/json"</strong> and <strong>Authorization="Bearer <em>
	your-</em>
				</strong>
				<em>
					<strong>auth-token</strong>
				</em>
				<strong>"</strong>. 
	Request body was just empty <strong>{}</strong>. Surely, request and response 
	body will be different for different APIs.</p>
	<p>Note that we also added X-Requested-With header to indicate that this is an AJAX request. Thus, ASP.NET Core can better handle the request and return appropriate return values on success and error cases.</p>
			<p>Almost all operations available on UI are also available as API and can be consumed easily.</p>
			<h3>Migrator Console Application</h3>
<p>Startup template includes a tool, Migrator.exe, to easily migrate your databases. 
You can run this application to create/migrate host and tenant databases.</p>
<p>
<img class="img-thumbnail" alt="Database Migrator" height="230" src="../images/database-migrator.png" width="659" /></p>
<p>This application gets host connection string from it's <strong>own 
		 appsettings.json 
            file</strong>. It will be same in the appsettings.json in the 
		 .Web.Host project at the beggining. Be sure that 
            the connection string in config file is the database you want. After getting
            <strong class="auto-style2">host </strong><strong>connection sring</strong>, it 
            first creates the host database or apply migrations if it does already exists. 
            Then it gets connection strings of tenant databases and runs migrations for 
            those databases. It skips a tenant if it has not a dedicated database or it's 
            database is already migrated for another tenant (for shared databases between 
            multiple tenants).
         </p>
			<p>You can use this tool on development or on product environment to 
            migrate databases on deployment, instead of EntityFramework's own 
            tooling (which requires some configuration and can work for 
            single database/tenant in one run).
         </p>
			<h3>Unit Testing</h3>
			<p>Startup template includes test infrastructure setup and a few tests under 
	the .Test project. You can check them and write similar tests easily. 
	Actually, they are integration tests rather than unit tests since they tests 
	your code with all ASP.NET Boilerplate infrastructure (including validation, 
	authorization, unit of work...).</p>
      <div class="document-contents">
		  <h3>Source Code</h3>
		  <p>This project template is developed as open source and free under 
		  Github:
		  <a href="https://github.com/aspnetboilerplate/module-zero-core-template">
		  https://github.com/aspnetboilerplate/module-zero-core-template</a></p>

      </div>

		</div>

	</body>

</html>
